package com.example.myapplication.finger_guess;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.R;

public class ResultActivity extends AppCompatActivity implements View.OnClickListener {
    Button btn;
    TextView tv1,tv2;
    ImageView iv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);
        initView();
        Intent intent = getIntent();
        String jia = intent.getStringExtra("jia");
        String yi = intent.getStringExtra("yi");
        judgeResult(jia,yi);
    }
    private void judgeResult(String jia, String yi) {
        if (jia.equals(yi)) {
            tv1.setText("甲乙平局");
            tv2.setText("甲乙平局");
            iv.setImageResource(R.mipmap.draw);
            return;
        }
        if((jia.equals("石头")&&yi.equals("剪刀"))||(jia.equals("布")||yi.equals("石头"))||(jia.equals("剪刀")&&yi.equals("布"))){
            tv1.setText("甲赢了");
            tv2.setText("甲赢了");
            iv.setImageResource(R.mipmap.ok);
            return;
        }
        tv1.setText("乙赢了");
        tv2.setText("乙赢了");
        iv.setImageResource(R.mipmap.ok);
    }
    private void initView() {
        btn = findViewById(R.id.btn_result);
        tv1 = findViewById(R.id.tv1_result);
        tv2 = findViewById(R.id.tv2_result);
        iv = findViewById(R.id.iv_result);
        btn.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        intent.setClass(this,JiaActivity.class);
        startActivity(intent);
        finish();
    }
}


